﻿// Copyright (c) 2012 - 2021 Jared Zheng <jaredz at outlook dot com>
// Buddha Framework is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
//
// Create : 2012-12-01 version 0.1 Jared Zheng <jaredz at outlook dot com>
// Update : 2021-03-19 version 4.0.0 Jared Zheng <jaredz at outlook dot com>

#include "stdafx.h"
#include "ServerSystem.h"
#include "MasterServer.h"
#include "SlaveServer.h"
#include "NodeServer.h"

///////////////////////////////////////////////////////////////////////////////////////////////////////////
// CServerSystem : CSubSystem
INLINE Int CServerSystem::GetComponentInfo(MAP_COMPONENT_INFO& Components) const
{
    Components.Add(UUID_OF( IMasterServer ), CStringKey(NAME_OF( IMasterServer )));
    Components.Add(UUID_OF( ISlaveServer ), CStringKey(NAME_OF( ISlaveServer )));
    Components.Add(UUID_OF( INodeServer ), CStringKey(NAME_OF( INodeServer )));

    return Components.GetSize();
}

INLINE bool CServerSystem::FindComponent(const CUUID& uuId) const
{
    if (uuId == UUID_OF( IMasterServer ))
    {
        return true;
    }
    else if (uuId == UUID_OF( ISlaveServer ))
    {
        return true;
    }
    else if (uuId == UUID_OF( INodeServer ))
    {
        return true;
    }
    return false;
}

INLINE bool CServerSystem::CreateComponent(const CUUID& uuId, CComponentPtr& CComponentPtrRef)
{
    CComponentPtrRef = nullptr;
    if (uuId == UUID_OF( IMasterServer ))
    {
        CMasterServer* pServer = MNEW CMasterServer;
        if (pServer != nullptr)
        {
            CComponentPtrRef = static_cast<ICommonFrame*>(pServer);
            return true;
        }
    }
    else if (uuId == UUID_OF( ISlaveServer ))
    {
        CSlaveServer* pServer = MNEW CSlaveServer;
        if (pServer != nullptr)
        {
            CComponentPtrRef = static_cast<ICommonFrame*>(pServer);
            return true;
        }
    }
    else if (uuId == UUID_OF( INodeServer ))
    {
        CNodeServer* pServer = MNEW CNodeServer;
        if (pServer != nullptr)
        {
            CComponentPtrRef = static_cast<ICommonFrame*>(pServer);
            return true;
        }
    }
    return false;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
// CreateSubSystem
CServerSystem   GServerSystem;

C_EXPORT CSubSystem* CreateSubSystem(const CUUID& uuId)
{
    if (uuId == UUID_OF( CServerSystem ))
    {
        return (&GServerSystem);
    }
    return nullptr;
}


